package com.darkplanet.management.controller;

import com.darkplanet.management.domain.Employee;
import com.darkplanet.management.domain.SecondMenu;
import com.darkplanet.management.service.EmployeeMenuImp;
import com.fasterxml.jackson.databind.ObjectMapper;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet(urlPatterns = "/GetEmployeeMenuServlet")
public class GetEmployeeMenuServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            doGet(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setCharacterEncoding("utf-8");
        List menus = (List)request.getSession().getAttribute("Menus");
        List<SecondMenu> fsecondMenus = (List<SecondMenu>) menus.get(1);
        ObjectMapper objectMapper = new ObjectMapper();
        String secondMenus = objectMapper.writeValueAsString(fsecondMenus);
        response.getWriter().print(secondMenus);
    }
}
